package com.huawei.hdfs;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import java.io.IOException;

public class IsFile {
    public static void main(String[] args) throws IOException {
        Configuration conf = new Configuration();
        //conf.set("fs.defaultFS", "hdfs:// master:9000");
        FileSystem fs = FileSystem.get(conf);
        Path path1 = new Path("/user/test/hdfs");
        Path path2 = new Path("/user/test/hdfs/file10.txt");
        //判断目录是否存在
        if (fs.exists(path1)) {
            System.out.println(path1+"目录已经存在");
        }else{
            System.out.println(path1+"目录不存在");
        }
        //判断文件是否存在
        if (fs.exists(path2)) {
            System.out.println(path2+"文件已经存在");
        }else{
            System.out.println(path2+"文件不存在");
        }
        fs.close();
    }
}